﻿/**
 * ...
 * @author Артём Григорьев
 */

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.xml.XML;
import flash.xml.XMLList;

typedef XMLloaderEvents = Event;

class XMLloader extends EventDispatcher
{
    
    public var xml:             Xml;
    private var urlLoader:      URLLoader;
    private var getting:        Bool;
    
    public function new():Void
    {
        super();
        getting = false;
    }
    
    
    public function load( url: String ):Void
    {
        getting                     = true;
        var urlRequest:URLRequest   = new URLRequest( url );
        urlLoader                   = new URLLoader();
        
        urlLoader.addEventListener( Event.COMPLETE, completeListener );
        urlLoader.load( urlRequest );
    }

    
    private function completeListener( e: Event ):Void
    {
        
        getting = false;
        xml = Xml.parse( urlLoader.data );
		
		for( child in xml ) {
			trace(child);
		}
		
        dispatchEvent( e );
        
    }
    

    
    
}